'use strict';
const SUN = require('../base/sun')
const WebSocket = require('ws')
const sessionMgr = require('./sessionMgr')
let gateConfig = SUN.serConfig.gateConfig

class GateServer {
    constructor() {
        this.server = null
    }
    //创建WS服务器
    createServer() {
        this.server = new WebSocket.Server({
            host: gateConfig.ip,
            port: gateConfig.port
        });
        console.info(`用户-网关服务器启动 ${gateConfig.ip}:${gateConfig.port}`)
        this.server.on('connection', function (socket) {
            //创建新的会话
            console.debug('新的用户连接')
            sessionMgr.create(socket)
        });
    }
}
let gateServer = new GateServer()

module.exports = gateServer
